package org.spring.cloud.stream.guide.springcloudstreamguide.tut1;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.stream.messaging.Source;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.scheduling.annotation.Scheduled;

public class Tut1Sender {
	

	int dots = 0;
    int count = 0;

	@Autowired
	private Source source;

	public void sayHello(String message) {
		source.output().send(MessageBuilder.withPayload(message).build());
	}
	
	@Scheduled(fixedDelay = 1000, initialDelay = 500)
	public void send() {
		StringBuilder builder = new StringBuilder("Hello");
        if (dots++ == 3) {
            dots = 1;
        }
       for (int i = 0; i < dots; i++) {
            builder.append('.');
        }

        builder.append(Integer.toString(++count));
        String message = builder.toString();
		System.out.println(" [x] Sent '" + message + "'");
	}

	public Source getSource() {
		return source;
	}

	public void setSource(Source source) {
		this.source = source;
	}
	
	

}
